using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using System.Xml;
using System.Threading;
using CookComputing.XmlRpc;

namespace uchomeDesktop
{
    /// <summary>
    /// Auch class
    /// </summary>
    class User : uchomeAPI
    {
        /// <summary>
        /// 
        /// </summary>
        public User() : base()
        {

        }

        /// <summary>
        /// login
        /// </summary>
        /// <param name="uname"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public Boolean login(string uname, string pwd)
        {
            // TODO: use muti-thread to REQUEST remote server
            try
            {
                loginResponse ret = proxy.login(uname, pwd);
                Properties.Settings.Default.auth = ret.authCode;
                Properties.Settings.Default.uid = ret.uid;
                Properties.Settings.Default.uname = ret.loginUser;

                return true;
            }
            catch
            {
                //MessageBox.Show(ee.Message);
                return false;
            }
        }

        /// <summary>
        /// logout
        /// </summary>
        /// <returns></returns>
        public Boolean logout()
        {
            try
            {
                logoutResponse ret = proxy.logout(auth);
                if (ret.code == "1")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch
            {
                return false;
            }
        }

        public userInfo getCurrentUserInfo()
        {
            string uid = Properties.Settings.Default.uid;
            userInfo ret = proxy.user_getInfo(auth, uid);
            return ret;
        }
    }
}
